﻿using HandyControl.Controls;
using HandyControl.Data;
using Infov1.ViewModels;
using System.Windows;
using System.Windows.Input;
using Infov1.Views;
using HandyControl.Tools.Extension;

namespace Infov1
{
    public partial class MainWindow : HandyControl.Controls.Window
    {
        private MainViewModel ViewModel => (MainViewModel)DataContext;

        public MainWindow()
        {
            InitializeComponent();
            txtUsername.Focus();

            // 由于 PasswordBox 的特殊性，需要手动绑定
            txtPassword.PasswordChanged += (s, e) =>
            {
                ViewModel.Password = txtPassword.Password;
            };
        }

        private void TxtUsername_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                txtPassword.Focus();
                e.Handled = true;
            }
        }

        private void TxtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ViewModel.LoginCommand.Execute(null);
                e.Handled = true;
            }
        }


        private void SqlLinkBtnClick(object sender, RoutedEventArgs e)
        {
            var sqlLinkView = new Infov1.Views.SqlLink();
            sqlLinkView.ShowDialog();
        }
    }
}